package de.dehuegel;

import java.util.LinkedList;
import java.util.List;
import java.util.Random;

enum Direction{
	RIGHT,LEFT
}

public class PlayingField{
	
	private int height;
	private int width;
	private int completedRows;
	private Tetramino currentTetramino;
	private List<Tetramino> tetraminos;
	private boolean [][] values;
	
	public PlayingField(int height,int width) {
		this.height=height;
		this.width=width;
		this.values=new boolean[height][width];
		this.setTetraminos(new LinkedList<Tetramino>());
	}

	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public int getWidht() {
		return width;
	}

	public void setWidht(int widht) {
		this.width = widht;
	}
	
	private Point2D getStartPoint(){
		int x=(int) (this.width/2.0);
		return new Point2D(x, 0);
	}
	
	private Tetramino getRandomTetramino(){
		Point2D startPoint=getStartPoint();
		Random random = new Random();
		Tetramino[] bricks=new Tetramino[]{new I(startPoint),new J(startPoint),new L(startPoint),new O(startPoint),new S(startPoint),new T(startPoint),new Z(startPoint)};		
		return bricks[random.nextInt(bricks.length-1)];
	}
	
	public void moveCurrentTetramino(Direction direction){
		switch (direction){
		case LEFT:
			;
		case RIGHT:
			;
		}
	}
	public void autoMoveDownCurrentBrick(){
		
	}
	private void updateValues(){
		for(Tetramino brick:this.tetraminos){
			for(int i=0;i<brick.getValues().length;i++){
				for(int j=0;j<brick.getValues()[0].length;j++){
					boolean value=this.values[brick.getPosition().getX()+i][brick.getPosition().getY()+j];
					if(brick.getValues()[i][j])
						value=true;

						
					
						
				}
			}
			
		}
	}
	private List<Tetramino> getNearTetramino(){
		return null;
	}
	
	public Tetramino addNewTetramino(){
		Tetramino newBrick = getRandomTetramino();
		this.tetraminos.add(newBrick);
		return newBrick;
	}

	public Tetramino getCurrentBrick() {
		return currentTetramino;
	}

	public void setCurrentBrick(Tetramino currentBrick) {
		this.currentTetramino = currentBrick;
	}

	public List<Tetramino> getBricks() {
		return tetraminos;
	}

	public void setTetraminos(List<Tetramino> bricks) {
		this.tetraminos = bricks;
	}

	public int getCompletedRows() {
		return completedRows;
	}

	public void setCompletedRows(int completedRows) {
		this.completedRows = completedRows;
	}
	

}
